import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
  {
    path: '/',
    name: 'home',
    component: () =>
    import ('../components/Main.vue'),
    redirect: '/index',
    children: [
      {
      path: '/index',
      name: 'index',
      component: () =>
          import ('../views/index/index.vue')
      },
      {
        path: '/list',
        name: 'list',
        component: () =>
            import ('../views/list/list.vue')
        },
      {
        path: '/login',
        name: 'test',
        component: () =>
            import ('../views/login/login.vue')
        },
      {
          path: '/detail',
          name: 'detail',
          component: () =>
              import ('../views/list/detail.vue')
        },
        {
          path: '/cart',
          name: 'cartPage',
          component: () =>
              import ('../views/cart/cartpage.vue')
        },
        {
          path: '/checkout',
          name: 'billpage',
          component: () =>
              import ('../views/bill/billpage.vue')
        },
        //userCenter
        {
          path: '/userCenter',
          name: 'userMain',
          component: () => 
              import ('../views/user/userMain.vue'),
          children: [
              {
              path: '/userCenter/userAccount',
              name: 'userAccount',
              component: () =>
                  import ('../views/user/detail/userAccount.vue')
              },
              {
                path: '/userCenter/userAddress',
                name: 'userAddress',
                component: () =>
                    import ('../views/user/detail/userAddress.vue')
                },
              {
                path: '/userCenter/userOrder',
                name: 'userOrder',
                component: () =>
                    import ('../views/user/detail/userOrder.vue'),
                children: [
                  {
                    path: '/userCenter/userOrder/orderAll',
                    name: 'orderAll',
                    component: () =>
                        import ('../views/user/detail/orderPage/orderAll.vue')
                  },
                  {
                    path: '/userCenter/userOrder/orderChecked',
                    name: 'orderChecked',
                    component: () =>
                        import ('../views/user/detail/orderPage/orderChecked.vue')
                  },
                  {
                    path: '/userCenter/userOrder/orderReceive',
                    name: 'orderReceive',
                    component: () =>
                        import ('../views/user/detail/orderPage/orderReceive.vue')
                  },
                  {
                    path: '/userCenter/userOrder/orderOver',
                    name: 'orderOver',
                    component: () =>
                        import ('../views/user/detail/orderPage/orderOver.vue')
                  },
                  {
                    path: '/userCenter/userOrder/orderAfterSale',
                    name: 'orderAfterSale',
                    component: () =>
                        import ('../views/user/detail/orderPage/orderAfterSale.vue')
                  },
                ]
              },
          ]
        },
    ],
  }
]

// router.beforeEach((to, from, next) => {
//   if (to.meta.requireAuth) {
//       if (sessionStorage.userInfo) { // 获取当前的token是否存在
//           next();
//       } else {
//           console.log("token不存在");
//           next({
//               path: '/', // 将跳转的路由path作为参数，登录成功后跳转到该路由
//               query: { redirect: to.fullPath }
//           })
//       }
//   } else {
//       next();
//   }

// })


const router = new Router({
  mode: 'history', // 生产环境:history  正式环境：hash
  routes
})
export default router